﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
using System.Management.Instrumentation;
namespace kiril_lib
{
    /**
     * Generates RGB values based on data obtained from the WiFi info
     * */
    public class Kiril
    {
        String a;
        String comp = "RSSI: -";
        float mappedValueR, mappedValueG, mappedValueB = 1;
        float mappedPrevR, mappedPrevG, mappedPrevB = 1;
        int rssiLog, lastrssiLog, rssiValue, lastrssiValue, mappedRssi = 0;

        int maxRssi = -40;
        int maxRssiBackup = -40;

        int minRssi = -80;
        int minRssiBackup = -80;


        float m = 0;

        bool shouldMap = false;
        bool init = false;
        int scanCounter;
        bool shouldScan = true;

        //ControlP5 cp5;
        int textXPos;
        int textYPos;
        bool calibrate = false;
        bool reset = false;

        //Textlabel myTextlabelA;
        //Textlabel myTextlabelB;

        int from, to, current;


        public float getHeatMapValueR(float value){

            

            if (value < 25) {
                float reading = (value - 0);
                float percentage = reading / 25;
                mappedValueR = 0;
            } else if (value >= 25 && value < 50) {
                float reading = (value - 25);
                float percentage = reading / 25;
                mappedValueR = 0;
            } else if (value >= 50 && value < 75) {
                float reading = (value - 50);
                float percentage = reading / 25;
                float inversePercentage = 1 - percentage;
                mappedValueR = 255 * percentage;
            } else if (value > 75) {
                float reading = (value - 75);
                float percentage = reading / 25;
                float inversePercentage = 1 - percentage;
                mappedValueR = 255.0f;
            }
            return Math.Abs(mappedValueR);

        }
        public float getHeatMapValueG( float value ) {
            if (value < 25) {
                float reading = (value - 0);
                float percentage = reading / 25;
                mappedValueG = 255 * percentage;
            } else if (value >= 25 && value < 50) {
                float reading = (value - 25);
                float percentage = reading / 25;
                mappedValueG = 255;
            } else if (value >= 50 && value < 75) {
                float reading = (value - 50);
                float percentage = reading / 25;
                float inversePercentage = 1 - percentage;
                mappedValueG = 255;
            } else if (value > 75) {
                float reading = (value - 75);
                float percentage = reading / 25;
                float inversePercentage = 1 - percentage;
                mappedValueG = 255 * inversePercentage;
            }
            return mappedValueG;
        }

        public float getHeatMapValueB( float value ) {
            if (value < 25) {
                float reading = (value - 0);
                float percentage = reading / 25;
                mappedValueB = 255.0f;
            } else if (value >= 25 && value < 50) {
                float reading = (value - 25);
                float percentage = reading / 25;
                float inversePercentage = 1 - percentage;
                mappedValueB = 255 * inversePercentage;
            } else if (value >= 50 && value < 75) {
                float reading = (value - 50);
                float percentage = reading / 25;
                float inversePercentage = 1 - percentage;
                mappedValueB = 0;
            } else if (value > 75) {
                float reading = (value - 75);
                float percentage = reading / 25;
                float inversePercentage = 1 - percentage;
                mappedValueB = 0;
            }
            return mappedValueB;
        }
    }
}
